//
//  WareUpdateViewController.m
//  project
//
//  Created by 圆圆陈 on 2018/3/6.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "WareUpdateViewController.h"
@interface WareUpdateViewController ()<UIAlertViewDelegate>
@end

@implementation WareUpdateViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [SN_Net getDeviceUpdateInfoFromServerWithSuccess:^(id object) {
        _discribleLabel.text = KK_BLEModel.bleOnlineVersion>KK_BLEModel.bleVersion?[NSString stringWithFormat:@"%@: V%ld",SN_Text(@"最新固件版本"),KK_BLEModel.bleOnlineVersion]:SN_Text(@"当前已为最新版本");
    } fail:^(id object) {
        
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
  
    UIImage *backImage = UIImageNamed(@"背景");
    UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), HHHWIDTH, HHHWIDTH*backImage.size.height/backImage.size.width)];
    backImageView.userInteractionEnabled = YES;
    backImageView.image = backImage;
    [self.view addSubview:backImageView];
    
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20),screenWidth, 44)];
    lable.textColor=[UIColor whiteColor];
    lable.font = SNFONT(17);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text = HHH_Text(@"固件更新");
    
    [self.view addSubview:lable];
    
    UIButton *leftButton = [[UIButton alloc] init];
    leftButton.frame = CGRectMake(5, 20+FitSimpleIpx(0, 20), 44, 44);

    [leftButton setImage:[UIImage imageWithImageName:@"进入"] forState:UIControlStateNormal];
    [leftButton setTintColor:[UIColor whiteColor]];
    [leftButton addTarget:self action:@selector(leftbuttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    
    _currentVLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, backImageView.bottom-FitH(50), HHHWIDTH, FitH(30))];
    _currentVLabel.text = [NSString stringWithFormat:@"%@: V%ld",HHH_Text(@"当前设备固件"),KK_BLEModel.bleVersion];
    _currentVLabel.font = SNFONT(17.0);
    _currentVLabel.textAlignment = NSTextAlignmentCenter;
    _currentVLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_currentVLabel];
    
    _discribleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, backImageView.bottom+FitH(20), HHHWIDTH, FitH(30))];
    _discribleLabel.text = @"";
    _discribleLabel.font = SNFONT(17.0);
    _discribleLabel.textAlignment = NSTextAlignmentCenter;
    _discribleLabel.textColor = [UIColor blackColor];
    [self.view addSubview:_discribleLabel];
    
    _updateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _updateBtn.frame = CGRectMake(FitW(10), HHHHEIGHT-FitH(80), HHHWIDTH-FitW(20), FitH(50));
    [_updateBtn setBackgroundColor:[UIColor blackColor]];
    [_updateBtn setTitleNormal:SN_Text(@"检查更新")];
    [_updateBtn setTitleColorNormal:[UIColor whiteColor]];
    [_updateBtn addTouchUpTarget:self action:@selector(btnClick)];
    _updateBtn.layer.cornerRadius = 5;
    _updateBtn.clipsToBounds = YES;
    [self.view addSubview:_updateBtn];
    
}
- (void)leftbuttonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)btnClick{
//    if (KK_BLEModel.bleOnlineVersion>KK_BLEModel.bleVersion) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SN_Text(@"确定开始更新？")
//                                                        message:@" " delegate:self
//                                              cancelButtonTitle:nil
//                                              otherButtonTitles:SN_Text(@"退出"),SN_Text(@"ok"), nil];
//        [[UIView appearance] setTintColor:UIColorRGB(72, 72, 72)];
//        [alert show];
//    }else{
//        SHOWMBProgressHUD(nil, SN_Text(@"当前已为最新版本"), nil, NO, 2.0);
//    }
    NSLog(@"升级界面点击了>>>>");
   
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    if (buttonIndex==1) {
//        if ([KK_BLEModel.chip containsString:@"nrf"])
//        {
//            UpdateFirmwareVc *vc = [[UpdateFirmwareVc alloc] init];
//            [self.navigationController pushViewController:vc animated:YES];
//        }
//        else if ([KK_BLEModel.chip containsString:@"da"])
//        {
//
//        }else if ([KK_BLEModel.chip containsString:@"syd"]){
//
//        }
//    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
